package jinyilw.swing.rlaf.ui.icon;

import java.awt.Component;
import java.awt.Graphics;
import java.io.Serializable;

import javax.swing.ButtonModel;
import javax.swing.Icon;
import javax.swing.JMenuItem;
import javax.swing.plaf.UIResource;

import jinyilw.swing.icon.LazyScaleIcon;
import jinyilw.swing.rlaf.UITools;

public class RadioButtonMenuItemIcon implements Icon, UIResource, Serializable
{
	private static final long serialVersionUID = -7614343446018204362L;
	static Icon lightRadioIcon = new LazyScaleIcon(
			RadioButtonMenuItemIcon.class, "radio_light.png");
	static Icon darkRadioIcon = new LazyScaleIcon(RadioButtonMenuItemIcon.class,
			"radio_dark.png");
	private Icon icon;
	private int w, h;

	public RadioButtonMenuItemIcon()
	{
		w = 18;
		h = 18;
	}

	@Override
	public void paintIcon(Component c, Graphics g, int x, int y)
	{
		JMenuItem b = (JMenuItem) c;
		ButtonModel model = b.getModel();
		// icon = IconSet.getIconSet().radioIcon;
		if (UITools.isLight() && !model.isArmed())
			icon = lightRadioIcon;
		else
			icon = darkRadioIcon;
		if (model.isSelected() || model.isPressed() && icon != null)
			icon.paintIcon(c, g, x, y);
	}

	@Override
	public int getIconWidth()
	{
		return w;
	}

	@Override
	public int getIconHeight()
	{
		return h;
	}
}
